const ajax = function(options ={
  url: '',
  type: 'get',
  data: {},
  success: function() {},
  error: function() {}
}) {
  if(options.url) {
    // 兼容 Ie
    const xhr = XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP')
    let data = options.data,
          url = options.url,
          type = options.type,
          dataArr = [];
    for(let k in data) {
      dataArr.push(k+ '=' + data[k]);
    }
    if(type === 'Get') {
      url = url + '?' + dataArr.join('&')
      xhr.open(type, url.replace(/\?&/g, ''), true)
      xhr.send()
    }
    if(type === 'POST') {
      xhr.open(type, url, true)
      XMLHttpRequest.setRequestHeader('')
    }
  }
}

const xhr = XMLHttpRequest ? new XMLHttpRequest() : ActiveXObject('Microsoft.XMLHTTP')
xhr.open('get', url, true)
xhr.send()
xhr.onLoad = function() {
  if(xhr.status === 200 || xhr.status === 304) {
    // 请求成功
  } else {
    // 失败
  }
}